문제
So I'll copy the question right over.
Given a non-empty array of integers, return the k most frequent elements.
Example 1: Input: nums = [1, 1, 1, 2, 2, 3], k = 2 Output: [1, 2]
Example 2: Input: nums = [1], k = 1 Output: [1]
Note: Assume k is always valid. The input array will always have k unique most frequent elements.
For example, if nums = [1, 1, 2, 2, 3, 3], k cannot be 2 because there are no 2 unique most frequent elements. Inthis example, the only valid k is 3.